﻿using System;
using System.ComponentModel.Composition;
using IntoNails.Infrastructure;
using Microsoft.Practices.Prism.Events;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Prism.ViewModel;

namespace IntoNails.Modules.AuditTrail.ViewModels
{
    [Export(typeof(IAuditTrailRibbonTabViewModel))]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public class AuditTrailRibbonTabViewModel : NotificationObject, IAuditTrailRibbonTabViewModel
    {
        #region Fields

        private readonly IEventAggregator _eventAggregator;
        private readonly IRegionManager _regionManager;

        private bool _isTabSelected;

        #endregion

        [ImportingConstructor]
        public AuditTrailRibbonTabViewModel(IEventAggregator eventAggregator, IRegionManager regionManager)
        {
            this._eventAggregator = eventAggregator;
            this._regionManager = regionManager;
        }

        #region Implementation of IHeaderInfoProvider<string>

        public string HeaderInfo
        {
            get { return "Audit Trail"; }
        }

        #endregion

        public bool IsTabSelected
        {
            get { return this._isTabSelected; }
            set
            {
                this._isTabSelected = value;

                if (value)
                {
                    Uri workspaceUri = new Uri("AuditTrailWorkspaceView", UriKind.Relative);
                    this._regionManager.RequestNavigate(RegionNames.WorkspaceRegion, workspaceUri);
                }

                base.RaisePropertyChanged(() => IsTabSelected);
            }
        }
    }
}
